﻿@model Nop.Web.Models.Common.AddressModel
@using Nop.Web.Framework;
<script type="text/javascript">
     $(function() {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function() {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
                //show progress
                $.mobile.showPageLoadingMsg();
                $.ajax({
                    cache:false,
                    type: "GET",
                    url: "@(Url.Action("GetStatesByCountryId", "Country"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function(id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        //hide progress
                        $.mobile.hidePageLoadingMsg();

                        //jQuery Mobile. If you manipulate a select via JavaScript, you must call the refresh method on it to update the visual styling.
                        ddlStates.selectmenu("refresh");
                    },
                    error:function (xhr, ajaxOptions, thrownError){
                        alert('Failed to retrieve states.');
                        //hide progress
                        $.mobile.hidePageLoadingMsg();
                    }  
                });
            });
        });
</script>
@Html.HiddenFor(model => model.Id)
@Html.HiddenFor(model => model.FirstNameDisabled)
@Html.HiddenFor(model => model.LastNameDisabled)
@Html.HiddenFor(model => model.EmailDisabled)
@Html.HiddenFor(model => model.CompanyDisabled)
@Html.HiddenFor(model => model.CountryDisabled)
@Html.HiddenFor(model => model.StateProvinceDisabled)
@Html.HiddenFor(model => model.CityDisabled)
@Html.HiddenFor(model => model.Address1Disabled)
@Html.HiddenFor(model => model.Address2Disabled)
@Html.HiddenFor(model => model.ZipPostalCodeDisabled)
@Html.HiddenFor(model => model.PhoneNumberDisabled)
@Html.HiddenFor(model => model.FaxNumberDisabled)
@if (!Model.FirstNameDisabled)
{
    <div>
        @Html.LabelFor(model => model.FirstName)
        @Html.EditorFor(model => model.FirstName)
        @Html.ValidationMessageFor(model => model.FirstName)
    </div>
}
@if (!Model.LastNameDisabled)
{
    <div>
        @Html.LabelFor(model => model.LastName)
        @Html.EditorFor(model => model.LastName)
        @Html.ValidationMessageFor(model => model.LastName)
    </div>
}
@if (!Model.EmailDisabled)
{
    <div>
        @Html.LabelFor(model => model.Email)
        @Html.EditorFor(model => model.Email)
        @Html.ValidationMessageFor(model => model.Email)
    </div>
}
@if (!Model.CompanyDisabled)
{
    <div>
        @Html.LabelFor(model => model.Company)
        @Html.EditorFor(model => model.Company)
        @Html.ValidationMessageFor(model => model.Company)
    </div>
}
@if (!Model.CountryDisabled)
{
    <div>
        @Html.LabelFor(model => model.CountryId)
        @Html.DropDownListFor(model => model.CountryId, Model.AvailableCountries)
        @Html.ValidationMessageFor(model => model.CountryId)
    </div>
}
@if (!Model.StateProvinceDisabled)
{
    <div>
        @Html.LabelFor(model => model.StateProvinceId)
        @Html.DropDownListFor(model => model.StateProvinceId, Model.AvailableStates)
        @Html.ValidationMessageFor(model => model.StateProvinceId)
    </div>
}
@if (!Model.CityDisabled)
{
    <div>
        @Html.LabelFor(model => model.City)
        @Html.EditorFor(model => model.City)
        @Html.ValidationMessageFor(model => model.City)
    </div>
}
@if (!Model.Address1Disabled)
{
    <div>
        @Html.LabelFor(model => model.Address1)
        @Html.EditorFor(model => model.Address1)
        @Html.ValidationMessageFor(model => model.Address1)
    </div>
}
@if (!Model.Address2Disabled)
{
    <div>
        @Html.LabelFor(model => model.Address2)
        @Html.EditorFor(model => model.Address2)
        @Html.ValidationMessageFor(model => model.Address2)
    </div>
}
@if (!Model.ZipPostalCodeDisabled)
{
    <div>
        @Html.LabelFor(model => model.ZipPostalCode)
        @Html.EditorFor(model => model.ZipPostalCode)
        @Html.ValidationMessageFor(model => model.ZipPostalCode)
    </div>
}
@if (!Model.PhoneNumberDisabled)
{
    <div>
        @Html.LabelFor(model => model.PhoneNumber)
        @Html.EditorFor(model => model.PhoneNumber)
        @Html.ValidationMessageFor(model => model.PhoneNumber)
    </div>
}
@if (!Model.FaxNumberDisabled)
{
    <div>
        @Html.LabelFor(model => model.FaxNumber)
        @Html.EditorFor(model => model.FaxNumber)
        @Html.ValidationMessageFor(model => model.FaxNumber)
    </div>
}
